﻿namespace Task33
{
    using System;

    class Task3
    {
        private static void FillMatrix(byte[,] matrix, int row)
        {
            int index = 0;
            string[] tempy = Console.ReadLine().Split();
            foreach (var element in tempy)
            {
                matrix[row, index] = byte.Parse(element);
                index++;
            }
        }

        static void Main()
        {
            int lines = int.Parse(Console.ReadLine());

            byte[,] matrix = new byte[lines,lines];
            
            for (int i = 0; i < 5; i++)
            {
                FillMatrix(matrix, i);
            }
            
            int[] counters = new int[10];

            for (int row = 0; row <= matrix.GetLength(0) - 5; row++)
            {
                if ((row + 5) < matrix.GetLength(0))
                {
                    FillMatrix(matrix, row + 5);
                }

                for (int col = 0; col <= matrix.GetLength(0) - 3; col++)
                {
                    if (matrix[row, col + 2] == 1 && matrix[row + 1, col + 1] == 1 && matrix[row + 1, col + 2] == 1 && matrix[row + 2, col] == 1 && matrix[row + 2, col + 2] == 1 && matrix[row + 3, col + 2] == 1 && matrix[row + 4, col + 2] == 1)
                    {
                        counters[1]++;
                    }
                    else if (matrix[row, col + 1] == 2 && matrix[row + 1, col] == 2 && matrix[row + 1, col + 2] == 2 && matrix[row + 2, col + 2] == 2 && matrix[row + 3, col + 1] == 2 && matrix[row + 4, col] == 2 && matrix[row + 4, col + 1] == 2 && matrix[row + 4, col + 2] == 2)
                    {
                        counters[2]++;
                    }
                    //else if (matrix[row, col + 1] == 0 && matrix[row, col] == 0 && matrix[row, col + 2] == 0 && matrix[row + 1, col] == 0 && matrix[row + 1, col + 2] == 0 && matrix[row + 2, col + 2] == 0 && matrix[row + 2, col] == 0 && matrix[row + 3, col + 2] == 0 && matrix[row + 3, col] == 0 && matrix[row + 4, col + 2] == 0 && matrix[row + 4, col] == 0 && matrix[row + 4, col + 1] == 0)
                    //{
                    //    counters[0]++;
                    //}
                    else if (matrix[row, col + 1] == 3 && matrix[row, col] == 3 && matrix[row, col + 2] == 3 && matrix[row + 1, col + 2] == 3 && matrix[row + 2, col + 1] == 3 && matrix[row + 2, col + 2] == 3 && matrix[row + 3, col + 2] == 3 && matrix[row + 4, col] == 3 && matrix[row + 4, col + 1] == 3 && matrix[row + 4, col + 2] == 3)
                    {
                        counters[3]++;
                    }
                    else if (matrix[row, col + 2] == 4 && matrix[row, col] == 4 && matrix[row + 1, col] == 4 && matrix[row + 1, col + 2] == 4 && matrix[row + 2, col] == 4 && matrix[row + 2, col + 1] == 4 && matrix[row + 2, col + 2] == 4 && matrix[row + 3, col + 2] == 4 && matrix[row + 4, col + 2] == 4)
                    {
                        counters[4]++;
                    }
                    else if (matrix[row, col + 1] == 5 && matrix[row, col] == 5 && matrix[row, col + 2] == 5 && matrix[row + 1, col] == 5 && matrix[row + 2, col] == 5 && matrix[row + 2, col + 1] == 5 && matrix[row + 2, col + 2] == 5 && matrix[row + 3, col + 2] == 5 && matrix[row + 4, col] == 5 && matrix[row + 4, col + 1] == 5 && matrix[row + 4, col + 2] == 5)
                    {
                        counters[5]++;
                    }
                    else if (matrix[row, col + 1] == 6 && matrix[row, col] == 6 && matrix[row, col + 2] == 6 && matrix[row + 1, col] == 6 && matrix[row + 2, col] == 6 && matrix[row + 2, col + 1] == 6 && matrix[row + 2, col + 2] == 6 && matrix[row + 3, col] == 6 && matrix[row + 3, col + 2] == 6 && matrix[row + 4, col] == 6 && matrix[row + 4, col + 1] == 6 && matrix[row + 4, col + 2] == 6)
                    {
                        counters[6]++;
                    }
                    else if (matrix[row, col + 1] == 7 && matrix[row, col] == 7 && matrix[row, col + 2] == 7 && matrix[row + 1, col + 2] == 7 && matrix[row + 2, col + 1] == 7 && matrix[row + 3, col + 1] == 7 && matrix[row + 4, col + 1] == 7)
                    {
                        counters[7]++;
                    }
                    else if (matrix[row, col + 1] == 8 && matrix[row, col] == 8 && matrix[row, col + 2] == 8 && matrix[row + 1, col] == 8 && matrix[row + 1, col + 2] == 8 && matrix[row + 2, col + 1] == 8 && matrix[row + 3, col] == 8 && matrix[row + 3, col + 2] == 8 && matrix[row + 4, col] == 8 && matrix[row + 4, col + 1] == 8 && matrix[row + 4, col + 2] == 8)
                    {
                        counters[8]++;
                    }
                    else if (matrix[row, col + 1] == 9 && matrix[row, col] == 9 && matrix[row, col + 2] == 9 && matrix[row + 1, col] == 9 && matrix[row + 1, col + 2] == 9 && matrix[row + 2, col + 1] == 9 && matrix[row + 2, col + 2] == 9 && matrix[row + 3, col + 2] == 9 && matrix[row + 4, col] == 9 && matrix[row + 4, col + 1] == 9 && matrix[row + 4, col + 2] == 9)
                    {
                        counters[9]++;
                    }
                }
            }

            int sum = 0;

            for (int i = 0; i < counters.Length; i++)
            {
                sum += (i * counters[i]);
            }

            Console.WriteLine(sum);
        }
    }
}